/* author : Milan Vaja 
*/

	var startDate, endDate, miliSeconds, secDiff, minDiff, hourDiff, dayDiff, secDiff, minDiff, hourDiff, myTimer, startTimerFlag;	
	var interval = 999,
		currentInterval = 1,
		flag = false;
	
	function updateBody_EH() {
		if (secDiff > 0) {
			secDiff--;
		} else {
			if (minDiff > 0 && secDiff==0) {
				minDiff--;
			}else{
				if (hourDiff > 0 && minDiff==0) {
					hourDiff--;
				}else{
					if(dayDiff>0 && hourDiff==0){
						dayDiff--;
					}else{
						clearInterval(myTimer);
					}
					hourDiff = 23;
				}
				minDiff = 59;
			}
			secDiff = 59;
		}
		
		if(flag) { 
			drawCountDownArc(dayDiff, hourDiff, minDiff, secDiff); 
		}
	}
		
	function startTimer(){
		clearInterval(startTimerFlag);
		flag = true;
		startDate = new Date();
		//endDate = new Date(2012, 13, 05, 00, 25, 45);		
		endDate = endDate_fetch;
		miliSeconds = endDate.getTime() - startDate.getTime();
		secDiff = Math.floor(miliSeconds / 1000);
		minDiff = Math.floor(secDiff / 60);
		hourDiff = Math.floor(minDiff / 60);
		dayDiff = Math.floor(hourDiff / 24);		
		secDiff = secDiff % 60;
		minDiff = minDiff % 60;
		hourDiff = hourDiff % 24;
		
		clearInterval(myTimer);
		myTimer = setInterval(updateBody_EH, interval * currentInterval);
	}
	
	if(!startTimerFlag){
		startTimerFlag = setInterval("startTimer();", 1000);
	}
